<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/25
 * Time: 16:25
 */
namespace common\sources\write\valueservice;

use Yii;
use common\models\craftsman\ValueService;

class ValueServiceAccess implements IValueServiceAccess
{
    public function addValueService($data)
    {
        return Yii::$app->db->createCommand()->insert('value_service', [
            'return_type' => $data['return_type'],
            'return_type_pepper' => $data['return_type_pepper'],
            'interval_time' => $data['interval_time'],
            'interval_pepper' => !empty($data['interval_pepper']) ? $data['interval_pepper'] : 0.00,
            'pub_timing' => !empty($data['pub_timing']) ? $data['pub_timing'] :0,
            'pub_timing_pepper' => !empty($data['pub_timing_pepper']) ? $data['pub_timing_pepper'] : 0.00,
            'end_timing' => !empty($data['end_timing']) ? $data['end_timing'] :0,
            'end_timing_pepper' =>!empty($data['end_timing_pepper']) ? $data['end_timing_pepper'] :0.00 ,
            'chat_type' => $data['chat_type'],
            'chat_pepper' => !empty($data['chat_pepper']) ? $data['chat_pepper'] : 0.00,
            'chat_keys' => $data['chat_keys'],
            'exten_period' => $data['exten_period'],
            'extend_pepper' =>  !empty($data['extend_pepper']) ? $data['extend_pepper'] : 0.00,
            'buy_sex' => !empty($data['buy_sex']) ? $data['buy_sex'] : 1 ,
            'sex_pepper' => !empty($data['sex_pepper']) ? $data['sex_pepper'] : 0.00,
            'buy_age' =>$data['buy_age'],
            'buy_age_pepper' => !empty($data['buy_age_pepper']) ? $data['buy_age_pepper'] : 0.00,
            'up_rank' => $data['up_rank'],
            'up_rank_pepper' => !empty($data['up_rank_pepper']) ? $data['up_rank_pepper'] : 0.00,
            'praise' => !empty($data['praise']) ? $data['praise'] : 1,
            'praise_keys' => !empty($data['praise_keys']) ? $data['praise_keys'] : '' ,
            'praise_pepper' => $data['praise_pepper'],
            'prohibit_pepper' => !empty($data['prohibit_pepper']) ? $data['prohibit_pepper'] : 0.00,
            'reword_commise' => $data['reword_commise'],
            'prio_audit' => $data['prio_audit'],
            'prio_audit_pepper' => !empty($data['prio_audit_pepper']) ? $data['prio_audit_pepper'] : 0.00,
            'expre_service' => $data['expre_service'],
            'service_pepper' => !empty($data['service_pepper']) ? $data['service_pepper'] : 0.00,
            'weight' => $data['weight'],
            'bus_id' => $data['bus_id'],
            'task_commod_id' => $data['task_commod_id'],
            'task_id' => $data['task_id'],
            'credit_card' => $data['credit_card'],
            'credit_card_pepper' => !empty($data['credit_card_pepper']) ? $data['credit_card_pepper'] : 0.00,
            'free_shipping' => $data['free_shipping'],
            'create_time' => time()
        ])->execute();
    }
    //修改增值服务
    public function modifyValueSevice($data)
    {
        $sql = 'UPDATE ' . ValueService::tableName() . ' SET return_type = :return_type,interval_time = :interval_time,pub_timing = :pub_timing,end_timing = :end_timing,chat_type = :chat_type,chat_keys = :chat_keys,exten_period = :exten_period,credit_card = :credit_card,buy_sex = :buy_sex,praise_keys = :praise_keys,buy_age = :buy_age,up_rank = :up_rank,reword_commise = :reword_commise,prio_audit = :prio_audit,expre_service = :expre_service,weight = :weight,free_shipping = :free_shipping,return_type_pepper = :return_type_pepper,interval_pepper = :interval_pepper,pub_timing_pepper = :pub_timing_pepper,end_timing_pepper = :end_timing_pepper,chat_pepper = :chat_pepper,extend_pepper = :extend_pepper,credit_card_pepper = :credit_card_pepper,sex_pepper = :sex_pepper,praise_pepper = :praise_pepper,up_rank_pepper = :up_rank_pepper,prohibit_pepper = :prohibit_pepper,prio_audit_pepper = :prio_audit_pepper,service_pepper = :service_pepper,praise = :praise,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':return_type' => $data['return_type'],
                ':interval_time' => $data['interval_time'],
                ':pub_timing' =>!empty($data['pub_timing']) ? $data['pub_timing'] :'0',
                ':end_timing' =>!empty($data['end_timing']) ? $data['end_timing'] :'0',
                ':chat_type' => $data['chat_type'],
                ':chat_keys' => $data['chat_keys'],
                ':exten_period' => $data['exten_period'],
                ':credit_card' => $data['credit_card'],
                ':buy_sex' => !empty($data['buy_sex']) ?$data['buy_sex'] : 1,
                ':praise_keys' => !empty($data['praise_keys']) ?$data['praise_keys'] : '',
                ':buy_age' => $data['buy_age'],
                ':up_rank' => $data['up_rank'],
                ':reword_commise' => $data['reword_commise'],
                ':prio_audit' => $data['prio_audit'],
                ':expre_service' => $data['expre_service'],
                ':weight' => $data['weight'],
                ':free_shipping' => $data['free_shipping'],
                ':return_type_pepper' => $data['return_type_pepper'],
                ':interval_pepper' => $data['interval_pepper'],
                ':pub_timing_pepper' => $data['pub_timing_pepper'],
                ':end_timing_pepper' => $data['end_timing_pepper'],
                ':chat_pepper' => $data['chat_pepper'],
                ':extend_pepper' => $data['extend_pepper'],
                ':credit_card_pepper' => $data['credit_card_pepper'],
                ':sex_pepper' => $data['sex_pepper'],
                ':praise_pepper' => $data['praise_pepper'],
                ':up_rank_pepper' => $data['up_rank_pepper'],
                ':prohibit_pepper' => $data['prohibit_pepper'],
                ':prio_audit_pepper' => $data['prio_audit_pepper'],
                ':service_pepper' => $data['service_pepper'],
                ':praise' =>!empty($data['praise']) ?$data['praise'] :'1',
                ':update_time' => time(),
                ':id' => $data['value_service_id']
            ])->execute();
    }
}